//
//  AdjustPriceViewController.m
//  LuxuryGoods
//
//  Created by DCQ on 2018/8/8.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "AdjustPriceViewController.h"
#import "ConOrReDetailModel.h"
#import "ConOrReListViewController.h"
#import "UserInfoModel.h"
#import "MessageListViewController.h"

@interface AdjustPriceViewController ()
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UILabel *currentPrice;
@property (strong, nonatomic) ConOrReGoodsModel * model;
@end

@implementation AdjustPriceViewController
- (instancetype)initWithModel:(ConOrReGoodsModel *)model{
    self = [super init];
    if (self) {
        self.model = model;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setNavigationItemTitle:@"调整价格"];
    self.currentPrice.text = [NSString stringWithFormat:@"当前价格：%@",self.model.sale_price];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)sureBtnAction:(id)sender {
    if (!self.textField.text || self.textField.text.length == 0) {
        [self showAlertView:@"请填写价格" withConfirmAction:nil];
        return;
    }
    NSDictionary * params = @{@"order_goods_id":self.model.order_goods_id,@"token":UserInfo.userToken,@"price":self.textField.text};
    
    [[MainApi sharedInstance] postPath:@"/Consignorder/changePrice" params:params resultBlock:^(NSDictionary *responseObject, NSError *error) {
        NSString * notificationName = @"";
        if (self.fromVCType == AdjustPriceViewFromVCType_Msg) {
            notificationName = @"UPDATE_MESSAGE_LIST";
        }else{
            notificationName = @"UPDATE_ConOrReOrder_LIST";
        }
        [[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:nil];
        
        for (UIViewController * tempVC in self.navigationController.viewControllers) {
            
            if ([tempVC isKindOfClass:[ConOrReListViewController class]]) {
                [self.navigationController popToViewController:tempVC animated:YES];
            }
            if ([tempVC isKindOfClass:[MessageListViewController  class]]) {
                [self.navigationController popToViewController:tempVC animated:YES];
            }
        }
    }];
   
 
}


@end
